<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/head::head"></th:block>
    <style>

        .context {
            height: 70vh;
        }

        /*textarea {*/
        /*    background-color: #373737 !important;*/
        /*    color: green;*/
        /*}*/
    </style>
</head>

<body>
<form action="" class="layui-form" id="form_ngx">
    <input type="hidden" name="genre" th:value="${type}">
    <div class="layui-form-item">
        <label class="layui-form-label">文件路径</label>
        <div class="layui-input-inline">
            <select name="whitePath" id="whitePath" required lay-verify="required"
                    th:disabled="${type=='update'}">
                <option value="">请选择白名单路径</option>

                <option th:each="item : ${nginx}" th:value="${item}" th:selected="${item==data?.whitePath}"
                        th:text="${item}">
                </option>
            </select>
        </div>
        <label class="layui-form-label">文件名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" placeholder='文件后缀必须为".conf"' class="layui-input"
                   th:disabled="${type=='update'}" th:value="${data?.name}" required lay-verify="required">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">配置内容</label>
        <div class="layui-input-block">
                        <textarea name="context" required lay-verify="required" placeholder="请填写nginx配置内容"
                                  class="layui-textarea context" th:text="${data?.context}"></textarea>
        </div>
    </div>
    <div class="layui-form-item" style="padding-left: 20%">
        <button class="layui-btn" lay-submit lay-filter="submitNgx" id="ngx_submit">提交
        </button>
    </div>
</form>
</body>
<script type="text/javascript"
        th:src="@{${session.jpomProxyPath}+'/static/js/auto-line-number.js?v='+${session.staticCacheTime}}"></script>

<script type="text/javascript">

    function loadSuccess() {
        initPlugin();
        $("textarea").setTextareaCount({
            width: "30px",
            bgColor: "#ddd",
            color: "#000",
            display: "inline-block"
        });

        //提交配置信息
        form.on('submit(submitNgx)', function (data) {
            loadingAjax({
                url: './updateNgx',
                data: data.field,
                success: function (data) {
                    layer.msg(data.msg);
                    if (data.code == 200) {
                        closeTab();
                    }
                }
            });
            return false;
        });
    }

    function closeTab() {
        try {
            top.frames["nginx"].location.reload();
        } catch (e) {
            console.error(e);
        }
        setTimeout(function () {
            var element = top.layui.element;
            var id = self.frameElement.getAttribute('id');
            element.tabDelete('mainTabs', id);
            element.tabChange('mainTabs', "tab_nginxnginx管理");
        }, 1500);
    }

</script>

</html>